package com.yijinsuo.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.yijinsuo.R;
import com.yijinsuo.base.BaseActivity;
import com.yijinsuo.base.ViewPagerIndicatorAdapter;
import com.yijinsuo.entity.BaoLiInfo;
import com.yijinsuo.entity.BorrowList;
import com.yijinsuo.fragment.ChanPinJieShaoFragment;
import com.yijinsuo.fragment.TouZiJiLuFragment;
import com.yijinsuo.fragment.XiangGuanWenJianFragment;
import com.yijinsuo.view.TitleBar;
import com.yijinsuo.view.ViewPagerIndicator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 投资 点击查看页面
 */
public class TouZiLookDetailsActivity extends BaseActivity {

    @Bind(R.id.titlebar)
    TitleBar titlebar;
    @Bind(R.id.id_stickynavlayout_indicator)
    ViewPagerIndicator mViewPagerindicator;
    @Bind(R.id.id_vp)
    ViewPager mviewPager;
    private BorrowList borroInfo;
    private BaoLiInfo mBaoLiInfo;
    //
    private List<Fragment> mTabContents = new ArrayList<Fragment>();
    private ViewPagerIndicatorAdapter mAdapter;
    private List<String> mDatas = Arrays.asList("产品介绍", "相关文件", "投资记录");
    //
    private ChanPinJieShaoFragment fragment;
    private XiangGuanWenJianFragment fragment2;
    private TouZiJiLuFragment fragment3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_tou_zi_look_details);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        borroInfo = (BorrowList) getIntent().getSerializableExtra("borroInfo");
        mBaoLiInfo = (BaoLiInfo) getIntent().getSerializableExtra("mBaoLiInfo");
        if(null!=borroInfo){
            titlebar.setTitleBar(R.drawable.back_selector, borroInfo.getBorrowTitle(), 0);
        }
        if(null!=mBaoLiInfo){
            titlebar.setTitleBar(R.drawable.back_selector, mBaoLiInfo.getBorrowTitle(), 0);
        }

    }

    @Override
    protected void initView() {
        fragment = new ChanPinJieShaoFragment();
        fragment2 = new XiangGuanWenJianFragment();
        fragment3 = new TouZiJiLuFragment();
        mTabContents.add(fragment);
        mTabContents.add(fragment2);
        mTabContents.add(fragment3);
        mAdapter = new ViewPagerIndicatorAdapter(getSupportFragmentManager(), mTabContents);

    }


    @Override
    protected void setData() {
        //设置Tab上的标题
        mViewPagerindicator.setTabItemTitles(mDatas);
        mviewPager.setAdapter(mAdapter);
        mviewPager.setOffscreenPageLimit(1);
        //设置关联的ViewPager
        mViewPagerindicator.setViewPager(mviewPager, 0);

    }

    @OnClick(R.id.titlebar_iv_back)
    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.titlebar_iv_back:

                finish();

                break;

            default:
        }
    }
}
